package cn.com.text.Adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import cn.com.text.Dao.MyPost;
import cn.com.text.Dao.News;
import cn.com.text.R;
import cn.com.text.Util.ImageHelper;

/**
 * Created by 86176 on 2021/12/30.
 */

public class MyPostAdapter extends ArrayAdapter<MyPost>{
    private int rescoureId;
    public MyPostAdapter(Context context, int textViewResourceId, List<MyPost> objects) {
        super(context,textViewResourceId,objects);
        this.rescoureId = textViewResourceId;
    }

    @NonNull
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyPost myPost = getItem(position);
        View view = LayoutInflater.from(getContext()).inflate(rescoureId,parent,false);
        ImageView imageView = (ImageView) view.findViewById(R.id.imageViewMyPost);
        TextView postTitle = (TextView) view.findViewById(R.id.textViewTitle);
        TextView postContent = (TextView) view.findViewById(R.id.textViewContent);
        imageView.setImageBitmap(ImageHelper.stringToBitmap(myPost.getImagePost()));
        postTitle.setText(myPost.getNewstitle());
        postContent.setText(myPost.getNewscontent());
        return view;
    }
}
